package com.markus.code.剑指offer;

/**
 * Author:markusZhang
 * Date:Create in 2020/9/2 17:31
 * todo: 数值的整数次方
 */
public class MyPow {
    public double myPow(double x, int n) {
        long b = n;
        if (b < 0){
            b = -b;
            x = 1/x;
        }
        double res = 1;
        while(b > 0){
            if ((b&1) == 1){
                res *= x;
            }
            x *= x;
            b >>= 1;
        }
        return res;
    }
}
